const request = require('../httprequest.js')

/**
 * 登录, 相关的接口
 * @param userName
 * @param passWord
 * @returns {Promise<unknown>}
 */
function login (userName, passWord) {
  const parameter = {
    data: {
      username: userName,
      password: passWord
    }
  }
  return request.post(`user/login`, parameter)
}

/**
 * 注册
 * @param userName
 * @param passWord
 * @param rePassWord
 * @returns {Promise<unknown>}
 */
function register (userName, passWord, rePassWord) {
  const parameter = {
    data: {
      username: userName,
      password: passWord,
      repassword: rePassWord
    }
  }
  return request.post(`user/register`, parameter)
}

/**
 * 退出
 * @param userName
 * @param passWord
 * @param rePassWord
 * @returns {Promise<unknown>}
 */
function logout () {
  return request.get(`user/logout/json`)
}

/**
 * 获取用户信息
 * @returns {Promise | Promise<unknown>}
 */
function getUserInfo () {
  return request.get(`lg/coin/userinfo/json`)
}

/**
 * 获取banner列表
 * @returns {Promise | Promise<unknown>}
 */
function getBanner () {
  return request.get(`banner/json`)
}

module.exports = {
  login: login,
  register: register,
  logout: logout,
  getUserInfo: getUserInfo
}
